import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ImagesConst } from "../../resource/ImagesConst";
import { UICompomentPool } from "../../../../com/mui/utils/UICompomentPool";
import { MoneyItem } from "../common/item/MoneyItem";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { SecTimerView } from "../common/SecTimerView";
import { VerifySprite } from "../common/valifyCode/VerifySprite";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { SCoinCopyVerificationCode } from "../../../../Message/Public/SCoinCopyVerificationCode";
import { Alert } from "../../../../com/mui/controls/Alert";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GBitmap } from "../../../../com/mui/controls/GBitmap";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
//class CoinCopyVerifyWindow
    
    export  class CoinCopyVerifyWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(310, 337);
            title = Language.getString(42024);
            titleHeight = 26;
            _isAddClolseButton = false;
            if (_closeBtn && _closeBtn.parent) 
            {
                _closeBtn.parent.removeChild(_closeBtn);
            }
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            var loc1=null;
            super.createDisposedChildrenImpl();
            this._bg = ObjCreate.createBg(18, 38, 273, 285, this);
            loc1 = GlobalStyle.textFormat1;
            loc1.leading = 5;
            this._tipText1 = ObjCreate.createTextField("", 33, 45, 240, 40, this, loc1);
            this._tipText1.multiline = true;
            this._tipText1.wordWrap = true;
            this._tipText1.text = Language.getString(42028);
            loc1 = GlobalStyle.textFormat6;
            loc1.size = 13;
            this._starBmp1 = ObjCreate.createGBitmap(ImagesConst.StarYellow, 33, 88, this);
            this._starText1 = ObjCreate.createTextField(Language.getString(42032), 57, 90, 70, 20, this, loc1);
            this._moneyItem1 = UICompomentPool.getUICompoment(MoneyItem);
            this._moneyItem1.update(0, EPrictUnit._EPriceUnitCoin);
            this._moneyItem1.x = 26;
            this._moneyItem1.y = 110;
            this.addChild(this._moneyItem1);
            this._moneyItem2 = UICompomentPool.getUICompoment(MoneyItem);
            this._moneyItem2.update(0, EPrictUnit._EPriceUnitCoinBind);
            this._moneyItem2.x = 114;
            this._moneyItem2.y = 110;
            this.addChild(this._moneyItem2);
            this._starBmp2 = ObjCreate.createGBitmap(ImagesConst.StarYellow, 33, 132, this);
            this._starText2 = ObjCreate.createTextField("", 57, 134, 200, 20, this, loc1);
            this._starText2.htmlText = Language.getString(42033);
            this._moneyItem3 = UICompomentPool.getUICompoment(MoneyItem);
            this._moneyItem3.update(0, EPrictUnit._EPriceUnitCoinBind);
            this._moneyItem3.x = 26;
            this._moneyItem3.y = 153;
            this.addChild(this._moneyItem3);
            this._lineBmp = ObjCreate.createBg(33, 175, 240, 2, this, "SplitLine");
            loc1 = new GTextFormat(FontUtil.songtiName, 13, 15788607, true);
            if (!this._secTimerView) 
            {
                this._secTimerView = new SecTimerView();
                this._secTimerView.setParse(Language.getString(42025));
                this._secTimerView.x = 38;
                this._secTimerView.y = 184;
                this._secTimerView.width = 130;
                this._secTimerView.height = 20;
                this._secTimerView.defaultTextFormat = loc1;
                this._secTimerView.selectable = false;
            }
            this.addChild(this._secTimerView);
            this._tipText2 = ObjCreate.createTextField("", 168, 184, 100, 20, this, GlobalStyle.textFormat1);
            this._tipText2.htmlText = Language.getStringByParam(42026, 3);
            this._verifySprite = UICompomentPool.getUICompoment(VerifySprite);
            this._verifySprite.x = 42;
            this._verifySprite.y = 210;
            this.addChild(this._verifySprite);
            this._textTipInput = ObjCreate.createGTextField(Language.getString(42034), 37, 287, 40, 20, this, GlobalStyle.textFormat1);
            this._inputText = ObjCreate.createGTextInput(80, 281, 140, 28, this);
            this._inputText.setStyle("textPadding", 5);
            this._btnSubmit = ObjCreate.createGButton(Language.getString(42027), 230, 284, 49, 22, this);
            this._verifySprite.configEventListener(flash.events.MouseEvent.CLICK, this.onClickVerfySprite);
            this._btnSubmit.configEventListener(flash.events.MouseEvent.CLICK, this.onClickSubmitBtn);
            return;
        }

        /* internal  */onClickVerfySprite(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CoinCopyChangeVerifyCode));
            return;
        }

        /* internal  */onClickSubmitBtn(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._inputText.text;
            if (!loc1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(42029));
                return;
            }
            if (loc1 == this._verifySprite.code) 
            {
                loc1 = this._verifyCode.code;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CoinCopySubmitVerifyCode, loc1));
            return;
        }

        public updateCode(arg1: SCoinCopyVerificationCode): void
        {
            var loc1=null;
            var loc2=0;
            this._verifyCode = arg1;
            if (arg1.code) 
            {
                this.show();
                this._moneyItem1.value = arg1.coin;
                this._moneyItem2.value = arg1.bindCoin;
                this._moneyItem3.value = arg1.coin * 0.2;
                if (this._verifySprite) 
                {
                    this._verifySprite.code = CoinCopyVerifyWindow.getCode();
                    this._tipText2.htmlText = Language.getStringByParam(42026, arg1.leftCount);
                    if (!this._secTimerView.running) 
                    {
                        this._secTimerView.setLeftTime(60);
                    }
                    this._inputText.text = "";
                }
                this._inputText.setFocus();
            }
            else 
            {
                if (arg1.coin > 0) 
                {
                    loc2 = arg1.coin * 0.2;
                    loc1 = Language.getStringByParam(42030, arg1.coin, arg1.bindCoin - loc2, loc2);
                }
                else 
                {
                    loc1 = Language.getStringByParam(42031, arg1.bindCoin);
                }
                Alert.show(loc1, null, Alert.OK);
                this._secTimerView.stop();
                this.hide();
            }
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._bg.dispose();
            this._tipText1.dispose();
            this._starBmp1.dispose(arg1);
            this._starText1.dispose(arg1);
            this._moneyItem1.dispose(arg1);
            this._moneyItem2.dispose(arg1);
            this._starBmp2.dispose(arg1);
            this._starText2.dispose(arg1);
            this._moneyItem3.dispose(arg1);
            this._lineBmp.dispose(arg1);
            this._verifySprite.dispose(arg1);
            this._inputText.dispose(arg1);
            this._btnSubmit.dispose(arg1);
            this._textTipInput.dispose(arg1);
            this._tipText2.dispose(arg1);
            this._bg = null;
            this._tipText1 = null;
            this._starBmp1 = null;
            this._starText1 = null;
            this._moneyItem1 = null;
            this._moneyItem2 = null;
            this._starBmp2 = null;
            this._starText2 = null;
            this._moneyItem3 = null;
            this._lineBmp = null;
            this._verifySprite = null;
            this._inputText = null;
            this._btnSubmit = null;
            this._textTipInput = null;
            this._tipText2 = null;
            super.disposeImpl(arg1);
            return;
        }

        /* internal  */static getCode(): string
        {
            var loc1=Language.getString(42035);
            var loc2="";
            var loc3=0;
            while (loc3 < 4) 
            {
                loc2 = loc2 + loc1.charAt(Math.floor(Math.random() * loc1.length));
                ++loc3;
            }
            return loc2;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_tipText1: GTextFiled;

        /* internal */ /* var */_starBmp1: GBitmap;

        /* internal */ /* var */_starText1: GTextFiled;

        /* internal */ /* var */_moneyItem1: MoneyItem;

        /* internal */ /* var */_moneyItem2: MoneyItem;

        /* internal */ /* var */_starBmp2: GBitmap;

        /* internal */ /* var */_starText2: GTextFiled;

        /* internal */ /* var */_moneyItem3: MoneyItem;

        /* internal */ /* var */_lineBmp: ScaleBitmap;

        /* internal */ /* var */_secTimerView: SecTimerView;

        /* internal */ /* var */_tipText2: GTextFiled;

        /* internal */ /* var */_verifySprite: VerifySprite;

        /* internal */ /* var */_textTipInput: GTextFiled;

        /* internal */ /* var */_inputText: GTextInput;

        /* internal */ /* var */_btnSubmit: GButton;

        /* internal */ /* var */_verifyCode: SCoinCopyVerificationCode;
    }
